<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>天气案例_深度监视</title>
    <!--引入Vue-->
    <script type="text/javascript" src="../js/vue.js"></script>
    <style>
        .basic {
            width: 400px;
            height: 100px;
            border: 1px solid black;
        }

        .happy {
            background-color: goldenrod;
        }

        .bad {
            background-color: black;
        }

        .normal {
            background-color: burlywood;
        }

        .atguigu1 {
            background-color: green;
        }

        .atguigu2 {
            font-size: large;
        }

        .atguigu3 {
            border-radius: 15px;
        }
    </style>
</head>
<body>
<!--准备好一个容器-->
<div class="root">
    <!--  绑定class样式--字符串写法，适用于：样式的类名不确定，需要动态指定  -->
    <div class="basic" :class="mood" @click="changeCss">{{name}}</div>
    <br/>
    <!--  绑定class样式--数组写法，适用于：样式的个数不确定，名字也不确定  -->
    <div class="basic" :class="classArr" @click="changeCss">{{name}}</div>
    <br/>
    <!--  绑定class样式--数组写法，适用于：样式的个数确定，名字也确定，但要动态决定用不用  -->
    <div class="basic" :class="classObj" @click="changeCss">{{name}}</div>
    <br/>
    <!--  绑定style样式--对象写法  -->
    <div class="basic" :style="styleObj">{{name}}</div>
</div>


<script type="text/javascript">
    Vue.config.productionTip = false //阻止Vue在启动时生成生成提示

    const vm = new Vue({
        el: '.root',
        data: function () {
            return {
                name: '尚硅谷',
                mood: 'happy',
                classArr: ['atguigu1', 'atguigu2', 'atguigu3'],
                classObj: {
                    atguigu1: false,
                    atguigu2: false,
                    atguigu3: false
                },
                styleObj: {
                    fontSize: '40px',
                    color: 'red',
                    backgroundColor: 'orange'
                }
            }
        },
        methods: {
            changeCss() {
                const arr = ['normal', 'happy', 'bad'];
                let index = null;
                do {
                    index = Math.floor(Math.random() * 3);
                } while (arr[index] == this.mood)
                this.mood = arr[index];
            }
        }
    })

</script>
</body>
</html>